package com.tencent.wework.demo.base

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import com.tencent.wework.list.R


/**
 * Created by huangwei on 2019/5/29.
 */
open class BaseListActivity :AppCompatActivity(){

    companion object{
        const val KEY_FRAGMENT_CLASS = "fragment_class"
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.list_activity)

        val fragmentClass = intent.getStringExtra(KEY_FRAGMENT_CLASS)
        val fragment:Fragment? = fragmentClass?.let {
            Fragment.instantiate(this@BaseListActivity, it)
        }?:initFragment()
        fragment?.apply {
            val bundle = intent.extras
            fragment.arguments = bundle
            supportFragmentManager.beginTransaction().replace(R.id.container, fragment).commit()
        }
    }

    open protected fun initFragment():Fragment?{
        return null
    }
}